import {
  IdCardValidatorMessage, licensePlateValidatorMessage,
  maxlengthValidationMessage, maxValidationMessage,
  minlengthValidationMessage,
  minValidationMessage, mobilePhoneValidatorMessage,
} from '@core/config/message-config.serivce';
import { ConfigOption } from '@ngx-formly/core';
import { IdCardValidator, licensePlateValidator, mobilePhoneValidator } from './ui-zorro.validator';
import { FormlyWrapperAddons } from './wrappers/addons';
import { TemplateDescription } from './run/description';
import { TemplateAddons } from './run/addon';

import {
  FormlyFieldCheckbox,
  FormlyFieldDate,
  FormlyFieldDateMonth,
  FormlyFieldDateYear,
  FormlyFieldDateRange,
  FormlyFieldInput,
  FormlyFieldInputExpression,
  FormlyFieldInputNumber,
  FormlyFieldMultiCheckbox,
  FormlyFieldRadio,
  FormlyFieldSelect,
  FormlyFieldSelectContract,
  FormlyFieldSelectEnumeration,
  FormlyFieldSelectBusiness,
  FormlyFieldTextArea,
  FormlyFieldCityPicker,
  FormlyFieldGrid,
  FormlyFieldSpan,
  FormlyFieldStatistic,
  FormlyFieldSteps,
  FormlyFieldList,
  FormlyFieldCharts,
  FormlyFieldLink,
  FormlyFieldConditionInput,
  FormlyFieldHr,
  FormlyFieldUpload,
  FormlyFieldTreeSelect,
  FormlyFieldSearchInput,
  FormlyFieldPlaceholder,
  FormlyFieldProgress,
  FormlyFieldDownload,
  FormlyFieldImportantNote,
  FormlyFieldCheckOpt,
  FormlyFieldSelectOperateGrid,
  FormlyFieldButton,
  FormlyFieldDrawer,
  FormlyFieldGridDisplay,
  FormlyFieldGridTable,
  // FormlyFieldCheckMaOptRedundancy,
  // FormlyFieldCheckMsOptRedundancy,
  // FormlyFieldCheckPaOptRedundancy,
  // FormlyFieldCheckPsOptRedundancy,
  ApesDrawerCustomComponent,
  ApesDialogImportWorkbookComponent,
  FormlyFieldCheckboxGroup, FormlyFieldTimeLine,
  FormlyFieldNote, FormlyFieldUploadForm,
  FormlyFieldTransfer,
  FormlyFieldSwitch,
  FormlyFieldCustomCard,
  FormlyFieldCustomCardDrawer
} from './types/types';

import {
  FormlyWrapperDescription,
  FormlyWrapperFieldset,
  FormlyWrapperLabel,
  FormlyWrapperSplit,
} from './wrappers/wrappers';
import { FormlyFieldTime } from '@shared/ui-zorro/src/types/time';
import { FormlyFieldUploadImages } from '@shared/ui-zorro/src/types/upload-images';
import { FormlyFieldCheckPzOptRedundancy } from '@shared/ui-zorro/src/types/check-pz-opt-redundancy';


export const FIELD_TYPE_COMPONENTS = [
  // types
  FormlyFieldInput,
  FormlyFieldInputExpression,
  FormlyFieldInputNumber,
  FormlyFieldCheckbox,
  FormlyFieldCheckboxGroup,
  FormlyFieldRadio,
  FormlyFieldSelect,
  FormlyFieldSelectContract,
  FormlyFieldSelectEnumeration,
  FormlyFieldSelectBusiness,
  FormlyFieldTextArea,
  FormlyFieldMultiCheckbox,
  FormlyFieldDate,
  FormlyFieldDateMonth,
  FormlyFieldDateYear,
  FormlyFieldDateRange,
  FormlyFieldCityPicker,
  FormlyFieldGrid,
  FormlyFieldGridTable,
  FormlyFieldSpan,
  FormlyFieldStatistic,
  FormlyFieldSteps,
  FormlyFieldList,
  FormlyFieldCharts,
  FormlyFieldLink,
  FormlyFieldHr,
  FormlyFieldTreeSelect,
  FormlyFieldUpload,
  FormlyFieldUploadImages,
  FormlyFieldUploadForm,
  FormlyFieldConditionInput,
  FormlyFieldSearchInput,
  FormlyFieldPlaceholder,
  FormlyFieldProgress,
  FormlyFieldDownload,
  FormlyFieldImportantNote,
  FormlyFieldCheckOpt,
  FormlyFieldSelectOperateGrid,
  // FormlyFieldCheckMaOptRedundancy,
  // FormlyFieldCheckMsOptRedundancy,
  // FormlyFieldCheckPaOptRedundancy,
  // FormlyFieldCheckPsOptRedundancy,
  FormlyFieldCheckPzOptRedundancy,
  // wrappers
  FormlyWrapperLabel,
  FormlyWrapperDescription,
  FormlyWrapperFieldset,
  FormlyWrapperSplit,
  FormlyWrapperAddons,
  FormlyFieldButton,
  FormlyFieldDrawer,
  ApesDrawerCustomComponent,
  ApesDialogImportWorkbookComponent,
  FormlyFieldGridDisplay,
  FormlyFieldTime,
  FormlyFieldTimeLine,
  FormlyFieldNote,
  FormlyFieldTransfer,
  FormlyFieldSwitch,
  FormlyFieldCustomCard,
  FormlyFieldCustomCardDrawer
];

export const ZORRO_FORMLY_CONFIG: ConfigOption = {
  types: [
    {
      name: 'input',
      component: FormlyFieldInput,
      wrappers: ['fieldset'],
    },
    {
      name: 'inputExpression',
      component: FormlyFieldInputExpression,
      wrappers: ['fieldset'],
    },
    {
      name: 'inputNumber',
      component: FormlyFieldInputNumber,
      wrappers: ['fieldset'],
    },
    {
      name: 'span',
      component: FormlyFieldSpan,
      wrappers: ['fieldset'],
    },
    {
      name: 'statistic',
      component: FormlyFieldStatistic,
      wrappers: ['fieldset'],
    },
    {
      name: 'steps',
      component: FormlyFieldSteps,
      wrappers: ['fieldset'],
    },
    {
      name: 'list',
      component: FormlyFieldList,
      wrappers: ['fieldset'],
    },
    {
      name: 'charts',
      component: FormlyFieldCharts,
      wrappers: ['fieldset'],
    },
    {
      name: 'link',
      component: FormlyFieldLink,
      wrappers: ['fieldset'],
    },
    {
      name: 'search',
      component: FormlyFieldSearchInput,
      wrappers: ['fieldset'],
    },
    {
      name: 'date',
      component: FormlyFieldDate,
      wrappers: ['fieldset'],
    },
    {
      name: 'dateMonth',
      component: FormlyFieldDateMonth,
      wrappers: ['fieldset'],
    },
    {
      name: 'dateYear',
      component: FormlyFieldDateYear,
      wrappers: ['fieldset'],
    },
    {
      name: 'dateRange',
      component: FormlyFieldDateRange,
      wrappers: ['fieldset'],
    },
    {
      name: 'time',
      component: FormlyFieldTime,
      wrappers: ['fieldset'],
    },
    {
      name: 'timeLine',
      component: FormlyFieldTimeLine,
      wrappers: ['fieldset'],
    },
    {
      name: 'note',
      component: FormlyFieldNote,
      // wrappers: ['fieldset'],
    },
    {
      name: 'checkbox',
      component: FormlyFieldCheckbox,
      wrappers: ['fieldset'],
    },
    {
      name: 'checkboxGroup',
      component: FormlyFieldCheckboxGroup,
      wrappers: ['fieldset'],
    },
    {
      name: 'radio',
      component: FormlyFieldRadio,
      wrappers: ['fieldset'],
      defaultOptions: {
        templateOptions: {
          options: [],
        },
      },
    },
    {
      name: 'select',
      component: FormlyFieldSelect,
      wrappers: ['fieldset'],
      defaultOptions: {
        templateOptions: {
          options: [],
        },
      },
    },
    {
      name: 'select-contract',
      component: FormlyFieldSelectContract,
      wrappers: ['fieldset'],
      defaultOptions: {
        templateOptions: {
          options: [],
        },
      },
    },
    {
      name: 'select-business',
      component: FormlyFieldSelectBusiness,
      wrappers: ['fieldset'],
      defaultOptions: {
        templateOptions: {
          options: [],
        },
      },
    },
    {
      name: 'textarea',
      component: FormlyFieldTextArea,
      wrappers: ['fieldset'],
      defaultOptions: {
        templateOptions: {
          cols: 1,
          rows: 1,
        },
      },
    },
    {
      name: 'multicheckbox',
      component: FormlyFieldMultiCheckbox,
      // wrappers: ['fieldset', 'label'],
      defaultOptions: {
        templateOptions: {
          options: [],
        },
      },
    },
    {
      name: 'grid',
      component: FormlyFieldGrid,
      // wrappers: ['split']
    },
    {
      name: 'grid-wrap',
      component: FormlyFieldGrid,
      wrappers: ['fieldset'],
    },
    {
      name: 'grid-display',
      component: FormlyFieldGridDisplay,
      wrappers: ['fieldset'],
    },
    {
      name: 'grid-table',
      component: FormlyFieldGridTable,
      wrappers: ['fieldset'],
    },
    {
      name: 'conditionInput',
      component: FormlyFieldConditionInput,
    },
    {
      name: 'checkOpt',
      component: FormlyFieldCheckOpt,
    },
    // {
    //   name: 'checkMaOptRedundancy',
    //   component: FormlyFieldCheckMaOptRedundancy
    // },  {
    //   name: 'checkMsOptRedundancy',
    //   component: FormlyFieldCheckMsOptRedundancy
    // }, {
    //   name: 'checkPaOptRedundancy',
    //   component: FormlyFieldCheckPaOptRedundancy
    // }, {
    //   name: 'checkPsOptRedundancy',
    //   component: FormlyFieldCheckPsOptRedundancy
    // },
    {
      name: 'checkPzOptRedundancy',
      component: FormlyFieldCheckPzOptRedundancy,
    },
    {
      name: 'tree-select',
      component: FormlyFieldTreeSelect,
      wrappers: ['fieldset'],
      defaultOptions: {
        templateOptions: {
          options: [],
        },
      },
    },
    {
      name: 'hr',
      component: FormlyFieldHr,
    },
    {
      name: 'upload',
      component: FormlyFieldUpload,
      wrappers: ['fieldset'],
    },
    {
      name: 'city-picker',
      component: FormlyFieldCityPicker,
      wrappers: ['fieldset'],
    },
    {
      name: 'select-enumeration',
      component: FormlyFieldSelectEnumeration,
      wrappers: ['fieldset'],
      defaultOptions: {
        expressionProperties: {
          'templateOptions.disabled': 'formState.states === "new"',
        },
      },
    },
    {
      name: 'placeholder',
      component: FormlyFieldPlaceholder,
    },
    {
      name: 'progress',
      component: FormlyFieldProgress,
    },
    {
      name: 'download',
      component: FormlyFieldDownload,
    },
    {
      name: 'important-note',
      component: FormlyFieldImportantNote,
      wrappers: ['fieldset'],
    },
    {
      name: 'select-operate-grid',
      component: FormlyFieldSelectOperateGrid,
      wrappers: ['fieldset'],
      defaultOptions: {
        templateOptions: {
          options: [],
        },
      },
    },
    {
      name: 'button',
      component: FormlyFieldButton,
      wrappers: ['fieldset'],
    },
    {
      name: 'switch',
      component: FormlyFieldSwitch,
      wrappers: ['fieldset'],
    },
    {
      name: 'drawer',
      component: FormlyFieldDrawer,
      wrappers: ['fieldset'],
    },
    {
      name: 'upload-images',
      component: FormlyFieldUploadImages,
      wrappers: ['fieldset'],
    },
    {
      name: 'upload-form',
      component: FormlyFieldUploadForm,
      wrappers: ['fieldset'],
    },
    {
      name: 'transfer',
      component: FormlyFieldTransfer,
      wrappers: ['fieldset'],
    },
    {
      name: 'custom-card',
      component: FormlyFieldCustomCard,
      wrappers: ['fieldset'],
    },
    {
      name: 'customCard-drawer',
      component: FormlyFieldCustomCardDrawer,
      wrappers: ['fieldset'],
    },
  ],
  wrappers: [
    { name: 'label', component: FormlyWrapperLabel },
    { name: 'description', component: FormlyWrapperDescription },
    { name: 'fieldset', component: FormlyWrapperFieldset },
    { name: 'split', component: FormlyWrapperSplit },
    { name: 'addons', component: FormlyWrapperAddons },
  ],
  manipulators: [
    { class: TemplateDescription, method: 'run' },
    { class: TemplateAddons, method: 'run' },
  ],
  validators: [
    { name: 'idCard', validation: IdCardValidator },
    { name: 'mobilePhone', validation: mobilePhoneValidator },
    { name: 'licensePlate', validation: licensePlateValidator },
  ],
  validationMessages: [
    { name: 'required', message: '该项为必填项目' },
    { name: 'minlength', message: minlengthValidationMessage },
    { name: 'maxlength', message: maxlengthValidationMessage },
    { name: 'min', message: minValidationMessage },
    { name: 'max', message: maxValidationMessage },
    { name: 'idCard', message: IdCardValidatorMessage },
    { name: 'mobilePhone', message: mobilePhoneValidatorMessage },
    { name: 'licensePlate', message: licensePlateValidatorMessage },
  ],
};
